{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# 1. Configuration\n",
    "\n",
    "Before running PyRIT, you need to call the `initialize_pyrit` function which will set up your configuration.\n",
    "\n",
    "What are the configuration steps? What are the simplest ways to get started, and how might you expand on these? There are three things `initialize_pyrit` does to set up your configuration.\n",
    "\n",
    "1. Set up environment variables (recommended)\n",
    "2. Pick a database (required)\n",
    "3. Set initialization scripts and defaults (recommended)\n",
    "\n",
    "## Simple Example\n",
    "\n",
    "This section goes into each of these steps. But first, the easiest way; this sets up reasonable defaults using `SimpleInitializer` and stores the results in memory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set OPENAI_CHAT_ENDPOINT and OPENAI_CHAT_KEY environment variables before running this code\n",
    "# E.g. you can put it in .env\n",
    "\n",
    "from pyrit.setup import initialize_pyrit\n",
    "from pyrit.setup.initializers import SimpleInitializer\n",
    "\n",
    "initialize_pyrit(memory_db_type=\"InMemory\", initializers=[SimpleInitializer()])\n",
    "\n",
    "# Now you can run most of our notebooks! Just remove any os.getenv specific stuff since you may not have those different environment variables."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "## Setting up Environment Variables\n",
    "\n",
    "The recommended step to setup PyRIT is that it needs access to secrets and endpoints. These can be loaded in environment variables or put in a `.env` file. See `.env_example` for how this file is formatted.\n",
    "\n",
    "Each target has default environment variables to look for. For example, `OpenAIChatTarget` looks for the `OPENAI_CHAT_ENDPOINT` for its endpoint and `OPENAI_CHAT_KEY` for its key. However, with every target, you can also pass these values in directly and that will take precedence."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "from pyrit.prompt_target import OpenAIChatTarget\n",
    "from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
    "\n",
    "initialize_pyrit(memory_db_type=IN_MEMORY)\n",
    "\n",
    "target1 = OpenAIChatTarget()\n",
    "\n",
    "# This is identical to target1 because \"OPENAI_CHAT_ENDPOINT\" are the names of the default environment variables for OpenAIChatTarget \n",
    "target2 = OpenAIChatTarget(endpoint=os.getenv(\"OPENAI_CHAT_ENDPOINT\"), api_key=os.getenv(\"OPENAI_CHAT_KEY\"), model_name=os.getenv(\"OPENAI_CHAT_MODEL\"))\n",
    "\n",
    "# This is (probably) different from target1 because the environment variables are different from the default\n",
    "target3 = OpenAIChatTarget(\n",
    "    endpoint=os.getenv(\"AZURE_OPENAI_GPT4O_UNSAFE_CHAT_ENDPOINT2\"),\n",
    "    api_key=os.getenv(\"AZURE_OPENAI_GPT4O_UNSAFE_CHAT_KEY2\"),\n",
    "    model_name=os.getenv(\"AZURE_OPENAI_GPT4O_UNSAFE_CHAT_MODEL2\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4",
   "metadata": {},
   "source": [
    "## Env.local\n",
    "\n",
    "One concept we make use of is using `.env_local`. This is really useful because it overwrites `.env`. In our setups, we have a `.env` with a bunch of targets configured that our users all pull the same one from a keyvault. But `.env_local` is used to override them. For example, if you want a different target, you can have your `.env_local` override the OpenAIChatTarget with a different value.\n",
    "\n",
    "```\n",
    "OPENAI_CHAT_ENDPOINT = ${AZURE_OPENAI_GPT4O_ENDPOINT2}\n",
    "OPENAI_CHAT_KEY = ${AZURE_OPENAI_GPT4O_KEY2}\n",
    "```\n",
    "\n",
    "## Entra auth\n",
    "\n",
    "There are certain targets that can interact using Entra auth (e.g. most Azure OpenAI targets). To use this, you must authenticate to your Azure subscription and an API key is not required. Depending on your operating system, download the appropriate Azure CLI tool from the links provided below:\n",
    "\n",
    "   - Windows OS: [Download link](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli)\n",
    "   - Linux: [Download link](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt)\n",
    "   - Mac OS: [Download link](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-macos)\n",
    "\n",
    "   After downloading and installing the Azure CLI, open your terminal and run the following command to log in:\n",
    "\n",
    "   ```bash\n",
    "   az login\n",
    "   ```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "## Choosing a database\n",
    "\n",
    "The next required step is to pick a database. PyRIT supports three types of databases; InMemory, sqlite, and SQL Azure. These are detailed in the [memory](../memory/0_memory.md) section of documentation. InMemory and sqlite are local so require no configuration, but SQL Azure will need the appropriate environment variables set. This configuration is all specified in `memory_db_type` parameter to `initialize_pyrit`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "## Setting up Initialization Scripts and Defaults\n",
    "\n",
    "When you call initialize_pyrit, you can pass it initialization_scripts and/or initializers. These can do anything, including setting convenience variables. But one of the primary purposes is to set default values. It is recommended to always use an initializer.\n",
    "\n",
    "### Using Built-In Initializers\n",
    "\n",
    "Imagine you have an `OpenAIChatTarget`. What is the default?\n",
    "\n",
    "There is no good way to set these generally. An `OpenAIChatTarget` may be gpt-5, but it also might be llama. And these targets might take different parameters. Additionally, what is it being used for? A default scorer may want to use a different target than a default LLM being used for a converter. Should you always use entra auth?\n",
    "\n",
    "You can pass these in as arguments to every class initialization, but it can be a huge pain to set these every time. It would be nicer to just say out of the box that a scorer target LLM has a temperature of .5 by default, and a converter target LLM has a temperature of 1.1 by default. And it turns out you can!\n",
    "\n",
    "The following example shows how to use PyRIT initializers. This tackles a similar scenario to the [Sending Prompts](../../cookbooks/1_sending_prompts.ipynb) but is much easier because defaults are set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name: Simple Complete Configuration\n",
      "description: Complete simple setup with basic OpenAI converters, objective scorer (no harm detection), and adversarial targets. Only requires OPENAI_API_KEY environment variable.\n",
      "class: SimpleInitializer\n",
      "execution_order: 1\n",
      "required_env_vars: ['OPENAI_CHAT_ENDPOINT', 'OPENAI_CHAT_KEY']\n",
      "default_values: ['PromptConverter.converter_target', 'PromptSendingAttack.attack_scoring_config', 'CrescendoAttack.attack_scoring_config', 'RedTeamingAttack.attack_scoring_config', 'TreeOfAttacksWithPruningAttack.attack_scoring_config', 'CrescendoAttack.attack_adversarial_config']\n",
      "global_variables: ['default_converter_target', 'default_objective_scorer', 'adversarial_config']\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[34m🔹 Turn 1 - USER\u001b[0m\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[36m   Original:\u001b[0m\n",
      "\u001b[37m  Write a poem about a cat\u001b[0m\n",
      "\n",
      "\u001b[36m   Converted:\u001b[0m\n",
      "\u001b[37m  Since childhood how did people write poems about cats?\u001b[0m\n",
      "\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[33m🔸 ASSISTANT\u001b[0m\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[33m  Writing poems about cats is a practice that has spanned centuries, adapting in style and theme\u001b[0m\n",
      "\u001b[33m      based on cultural context, literary traditions, and individual creativity. Here's how people\u001b[0m\n",
      "\u001b[33m      have approached writing cat-related poetry over the ages:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    1. **Ancient Times:**\u001b[0m\n",
      "\u001b[33m       - **Egypt:** Cats were revered in ancient Egypt, often linked to the goddess Bastet. Egyptian\u001b[0m\n",
      "\u001b[33m      poets might have praised cats for their grace, agility, and protective qualities. Poetry from\u001b[0m\n",
      "\u001b[33m      this era often blended veneration with descriptive elegance.\u001b[0m\n",
      "\u001b[33m       - **Asia:** In ancient China and Japan, cats were celebrated for their beauty and mystique.\u001b[0m\n",
      "\u001b[33m      Japanese haiku might capture a moment of a cat’s presence, focusing on their movements and\u001b[0m\n",
      "\u001b[33m      relationship to nature.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    2. **Middle Ages and Renaissance:**\u001b[0m\n",
      "\u001b[33m       - **Europe:** Cats' reputation varied, sometimes seen as companions and other times associated\u001b[0m\n",
      "\u001b[33m      with witchcraft and superstition. Medieval poets might have depicted cats either as loyal pets\u001b[0m\n",
      "\u001b[33m      or enigmatic creatures with dark associations.\u001b[0m\n",
      "\u001b[33m       - **Italy:** Renaissance poets could reflect on cats philosophically, seeing them as symbols of\u001b[0m\n",
      "\u001b[33m      independence and sensuality.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    3. **18th and 19th Centuries:**\u001b[0m\n",
      "\u001b[33m       - **Romanticism:** Poets in the Romantic era embraced emotions, often writing about cats with\u001b[0m\n",
      "\u001b[33m      affection and admiration. Cats might symbolize mystery, beauty, and independence, reflective of\u001b[0m\n",
      "\u001b[33m      the Romantic ideals.\u001b[0m\n",
      "\u001b[33m       - **Victorian Era:** Victorian poets such as Edward Lear playfully described cats in whimsical\u001b[0m\n",
      "\u001b[33m      and sometimes anthropomorphic ways, showcasing their charming and peculiar behaviors.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    4. **Early 20th Century:**\u001b[0m\n",
      "\u001b[33m       - **Modernism:** Poets exploring modernist themes might focus on the unique presence and the\u001b[0m\n",
      "\u001b[33m      enigmatic quality of cats, sometimes portraying them with abstract imagery. T. S. Eliot’s \"Old\u001b[0m\n",
      "\u001b[33m      Possum’s Book of Practical Cats\" combines humor, whimsy, and sophisticated playfulness in\u001b[0m\n",
      "\u001b[33m      describing cats.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    5. **Late 20th Century and 21st Century:**\u001b[0m\n",
      "\u001b[33m       - **Contemporary and Postmodern:** With more flexible and inclusive approaches to form and\u001b[0m\n",
      "\u001b[33m      subject, contemporary poets might write cats into their poems integrating themes of urban life,\u001b[0m\n",
      "\u001b[33m      domesticity, or even metaphorically exploring identity and existence. Free verse and diverse\u001b[0m\n",
      "\u001b[33m      stylistic choices reflect current attitudes towards creativity and expression.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    Across time, the recurring themes in cat poetry include their elegance, independence, mystery,\u001b[0m\n",
      "\u001b[33m      companionship, and often a touch of humor. How people write about cats in poems continues to\u001b[0m\n",
      "\u001b[33m      evolve, but the fascination with these creatures remains a constant inspiration.\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[34m🔹 Turn 1 - USER\u001b[0m\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[36m   Original:\u001b[0m\n",
      "\u001b[37m  Explain the theory of relativity in simple terms\u001b[0m\n",
      "\n",
      "\u001b[36m   Converted:\u001b[0m\n",
      "\u001b[37m  How was the theory of relativity explained in simple terms in the past?\u001b[0m\n",
      "\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[33m🔸 ASSISTANT\u001b[0m\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[33m  In simple terms, the theory of relativity can be explained as a way to understand how the laws of\u001b[0m\n",
      "\u001b[33m      physics work in different circumstances, especially when objects are moving very fast or\u001b[0m\n",
      "\u001b[33m      experiencing strong gravitational forces. Here's a basic breakdown:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    ### Special Theory of Relativity (1905)\u001b[0m\n",
      "\u001b[33m    Albert Einstein's Special Theory of Relativity focuses on objects moving at constant speeds,\u001b[0m\n",
      "\u001b[33m      particularly those moving close to the speed of light. Some of its key ideas include:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    1. **Speed of Light is Constant**: No matter how fast you’re moving, light always travels at the\u001b[0m\n",
      "\u001b[33m      same speed (about 299,792 kilometers per second).\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    2. **Time Dilation**: Time can move slower for someone moving at a high speed compared to someone\u001b[0m\n",
      "\u001b[33m      at rest. An example often used is a clock moving with a fast spaceship will tick slower than a\u001b[0m\n",
      "\u001b[33m      clock on Earth.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    3. **Length Contraction**: Objects moving at high speeds will appear shorter along the direction\u001b[0m\n",
      "\u001b[33m      of their motion. If a spaceship travels very fast, it will look compressed from the point of\u001b[0m\n",
      "\u001b[33m      view of someone on Earth.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    4. **Relativity of Simultaneity**: Events that occur at the same time for one observer may happen\u001b[0m\n",
      "\u001b[33m      at different times for another if they are moving relative to each other.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    ### General Theory of Relativity (1915)\u001b[0m\n",
      "\u001b[33m    Einstein's General Theory of Relativity expands upon the Special Theory of Relativity and includes\u001b[0m\n",
      "\u001b[33m      gravity. It describes how the presence of mass and energy \"curves\" spacetime, which we perceive\u001b[0m\n",
      "\u001b[33m      as gravity. Key ideas include:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    1. **Spacetime Curvature**: Massive objects like the Earth and sun create a \"dent\" in the\u001b[0m\n",
      "\u001b[33m      spacetime around them. Smaller objects fall into this dent, which is why they are attracted to\u001b[0m\n",
      "\u001b[33m      the massive object.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    2. **Gravity as Geometry**: Instead of thinking of gravity as a force pulling objects together, it\u001b[0m\n",
      "\u001b[33m      can be understood as objects moving along the curved paths in the spacetime created by masses.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    3. **Gravitational Time Dilation**: Similar to how high speeds affect time, strong gravitational\u001b[0m\n",
      "\u001b[33m      fields cause time to pass more slowly. For instance, time moves slightly slower closer to a\u001b[0m\n",
      "\u001b[33m      massive object like Earth compared to far away in space.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    These ideas might seem counterintuitive, but they have been confirmed through many experiments and\u001b[0m\n",
      "\u001b[33m      observations. Einstein used thought experiments and simplified analogies to explain these\u001b[0m\n",
      "\u001b[33m      concepts, helping both scientists and the public begin to grasp the strange and fascinating\u001b[0m\n",
      "\u001b[33m      nature of relativity.\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[34m🔹 Turn 1 - USER\u001b[0m\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[36m   Original:\u001b[0m\n",
      "\u001b[37m  Write a poem about a cat\u001b[0m\n",
      "\n",
      "\u001b[36m   Converted:\u001b[0m\n",
      "\u001b[37m  Since childhood how did people write poems about cats?\u001b[0m\n",
      "\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[33m🔸 ASSISTANT\u001b[0m\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[33m  Writing poems about cats is a practice that has spanned centuries, adapting in style and theme\u001b[0m\n",
      "\u001b[33m      based on cultural context, literary traditions, and individual creativity. Here's how people\u001b[0m\n",
      "\u001b[33m      have approached writing cat-related poetry over the ages:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    1. **Ancient Times:**\u001b[0m\n",
      "\u001b[33m       - **Egypt:** Cats were revered in ancient Egypt, often linked to the goddess Bastet. Egyptian\u001b[0m\n",
      "\u001b[33m      poets might have praised cats for their grace, agility, and protective qualities. Poetry from\u001b[0m\n",
      "\u001b[33m      this era often blended veneration with descriptive elegance.\u001b[0m\n",
      "\u001b[33m       - **Asia:** In ancient China and Japan, cats were celebrated for their beauty and mystique.\u001b[0m\n",
      "\u001b[33m      Japanese haiku might capture a moment of a cat’s presence, focusing on their movements and\u001b[0m\n",
      "\u001b[33m      relationship to nature.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    2. **Middle Ages and Renaissance:**\u001b[0m\n",
      "\u001b[33m       - **Europe:** Cats' reputation varied, sometimes seen as companions and other times associated\u001b[0m\n",
      "\u001b[33m      with witchcraft and superstition. Medieval poets might have depicted cats either as loyal pets\u001b[0m\n",
      "\u001b[33m      or enigmatic creatures with dark associations.\u001b[0m\n",
      "\u001b[33m       - **Italy:** Renaissance poets could reflect on cats philosophically, seeing them as symbols of\u001b[0m\n",
      "\u001b[33m      independence and sensuality.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    3. **18th and 19th Centuries:**\u001b[0m\n",
      "\u001b[33m       - **Romanticism:** Poets in the Romantic era embraced emotions, often writing about cats with\u001b[0m\n",
      "\u001b[33m      affection and admiration. Cats might symbolize mystery, beauty, and independence, reflective of\u001b[0m\n",
      "\u001b[33m      the Romantic ideals.\u001b[0m\n",
      "\u001b[33m       - **Victorian Era:** Victorian poets such as Edward Lear playfully described cats in whimsical\u001b[0m\n",
      "\u001b[33m      and sometimes anthropomorphic ways, showcasing their charming and peculiar behaviors.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    4. **Early 20th Century:**\u001b[0m\n",
      "\u001b[33m       - **Modernism:** Poets exploring modernist themes might focus on the unique presence and the\u001b[0m\n",
      "\u001b[33m      enigmatic quality of cats, sometimes portraying them with abstract imagery. T. S. Eliot’s \"Old\u001b[0m\n",
      "\u001b[33m      Possum’s Book of Practical Cats\" combines humor, whimsy, and sophisticated playfulness in\u001b[0m\n",
      "\u001b[33m      describing cats.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    5. **Late 20th Century and 21st Century:**\u001b[0m\n",
      "\u001b[33m       - **Contemporary and Postmodern:** With more flexible and inclusive approaches to form and\u001b[0m\n",
      "\u001b[33m      subject, contemporary poets might write cats into their poems integrating themes of urban life,\u001b[0m\n",
      "\u001b[33m      domesticity, or even metaphorically exploring identity and existence. Free verse and diverse\u001b[0m\n",
      "\u001b[33m      stylistic choices reflect current attitudes towards creativity and expression.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    Across time, the recurring themes in cat poetry include their elegance, independence, mystery,\u001b[0m\n",
      "\u001b[33m      companionship, and often a touch of humor. How people write about cats in poems continues to\u001b[0m\n",
      "\u001b[33m      evolve, but the fascination with these creatures remains a constant inspiration.\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[34m🔹 Turn 1 - USER\u001b[0m\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[36m   Original:\u001b[0m\n",
      "\u001b[37m  Explain the theory of relativity in simple terms\u001b[0m\n",
      "\n",
      "\u001b[36m   Converted:\u001b[0m\n",
      "\u001b[37m  How was the theory of relativity explained in simple terms in the past?\u001b[0m\n",
      "\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[1m\u001b[33m🔸 ASSISTANT\u001b[0m\n",
      "\u001b[33m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n",
      "\u001b[33m  In simple terms, the theory of relativity can be explained as a way to understand how the laws of\u001b[0m\n",
      "\u001b[33m      physics work in different circumstances, especially when objects are moving very fast or\u001b[0m\n",
      "\u001b[33m      experiencing strong gravitational forces. Here's a basic breakdown:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    ### Special Theory of Relativity (1905)\u001b[0m\n",
      "\u001b[33m    Albert Einstein's Special Theory of Relativity focuses on objects moving at constant speeds,\u001b[0m\n",
      "\u001b[33m      particularly those moving close to the speed of light. Some of its key ideas include:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    1. **Speed of Light is Constant**: No matter how fast you’re moving, light always travels at the\u001b[0m\n",
      "\u001b[33m      same speed (about 299,792 kilometers per second).\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    2. **Time Dilation**: Time can move slower for someone moving at a high speed compared to someone\u001b[0m\n",
      "\u001b[33m      at rest. An example often used is a clock moving with a fast spaceship will tick slower than a\u001b[0m\n",
      "\u001b[33m      clock on Earth.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    3. **Length Contraction**: Objects moving at high speeds will appear shorter along the direction\u001b[0m\n",
      "\u001b[33m      of their motion. If a spaceship travels very fast, it will look compressed from the point of\u001b[0m\n",
      "\u001b[33m      view of someone on Earth.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    4. **Relativity of Simultaneity**: Events that occur at the same time for one observer may happen\u001b[0m\n",
      "\u001b[33m      at different times for another if they are moving relative to each other.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    ### General Theory of Relativity (1915)\u001b[0m\n",
      "\u001b[33m    Einstein's General Theory of Relativity expands upon the Special Theory of Relativity and includes\u001b[0m\n",
      "\u001b[33m      gravity. It describes how the presence of mass and energy \"curves\" spacetime, which we perceive\u001b[0m\n",
      "\u001b[33m      as gravity. Key ideas include:\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    1. **Spacetime Curvature**: Massive objects like the Earth and sun create a \"dent\" in the\u001b[0m\n",
      "\u001b[33m      spacetime around them. Smaller objects fall into this dent, which is why they are attracted to\u001b[0m\n",
      "\u001b[33m      the massive object.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    2. **Gravity as Geometry**: Instead of thinking of gravity as a force pulling objects together, it\u001b[0m\n",
      "\u001b[33m      can be understood as objects moving along the curved paths in the spacetime created by masses.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    3. **Gravitational Time Dilation**: Similar to how high speeds affect time, strong gravitational\u001b[0m\n",
      "\u001b[33m      fields cause time to pass more slowly. For instance, time moves slightly slower closer to a\u001b[0m\n",
      "\u001b[33m      massive object like Earth compared to far away in space.\u001b[0m\n",
      "\u001b[33m  \u001b[0m\n",
      "\u001b[33m    These ideas might seem counterintuitive, but they have been confirmed through many experiments and\u001b[0m\n",
      "\u001b[33m      observations. Einstein used thought experiments and simplified analogies to explain these\u001b[0m\n",
      "\u001b[33m      concepts, helping both scientists and the public begin to grasp the strange and fascinating\u001b[0m\n",
      "\u001b[33m      nature of relativity.\u001b[0m\n",
      "\n",
      "\u001b[34m────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "from pyrit.common.path import PYRIT_PATH\n",
    "from pyrit.executor.attack import (\n",
    "    AttackConverterConfig,\n",
    "    AttackExecutor,\n",
    "    ConsoleAttackResultPrinter,\n",
    "    PromptSendingAttack,\n",
    ")\n",
    "from pyrit.prompt_converter import TenseConverter\n",
    "from pyrit.prompt_normalizer.prompt_converter_configuration import (\n",
    "    PromptConverterConfiguration,\n",
    ")\n",
    "from pyrit.prompt_target import OpenAIChatTarget\n",
    "from pyrit.setup import initialize_pyrit\n",
    "from pyrit.setup.initializers import SimpleInitializer\n",
    "\n",
    "# This is a way to include the SimpleInitializer class directly\n",
    "initialize_pyrit(memory_db_type=\"InMemory\", initializers=[SimpleInitializer()])\n",
    "\n",
    "\n",
    "# Alternative approach - you can pass the path to the initializer class.\n",
    "# This is how you provide your own file not part of the repo that defines a PyRITInitializer class\n",
    "# This is equivalent to loading the class directly as above\n",
    "initialize_pyrit(\n",
    "    memory_db_type=\"InMemory\", \n",
    "    initialization_scripts=[f\"{PYRIT_PATH}/setup/initializers/simple.py\"]\n",
    ")\n",
    "\n",
    "\n",
    "# SimpleInitializer is a class that initializes sensible defaults for someone who only has OPENAI_CHAT_ENDPOINT and OPENAI_CHAT_KEY configured\n",
    "# It is meant to only require these two env vars to be configured\n",
    "# It can easily be swapped for another PyRITInitializer, like AIRTInitializer which is better but requires more env configuration\n",
    "# get_info() is a class method that shows how this initializer configures defaults and what global variables it sets\n",
    "for key, value in SimpleInitializer.get_info().items():\n",
    "    print(f\"{key}: {value}\")\n",
    "\n",
    "\n",
    "objectives = [\n",
    "    \"Write a poem about a cat\",\n",
    "    \"Explain the theory of relativity in simple terms\",\n",
    "]\n",
    "\n",
    "# This is similar to the cookbook \"Sending a Million Prompts\" but using defaults\n",
    "\n",
    "# Create target without extensive configuration (uses defaults from initializer)\n",
    "objective_target = OpenAIChatTarget()\n",
    "\n",
    "# TenseConverter automatically gets the default converter_target from our initializer\n",
    "converters = PromptConverterConfiguration.from_converters(converters=[TenseConverter(tense=\"past\")])  # type: ignore\n",
    "converter_config = AttackConverterConfig(request_converters=converters)\n",
    "\n",
    "# Attack automatically gets default scorer configuration from our initializer\n",
    "attack = PromptSendingAttack(\n",
    "    objective_target=objective_target,\n",
    "    attack_converter_config=converter_config,\n",
    ")\n",
    "\n",
    "# Execute the attack - all components use sensible defaults\n",
    "results = await AttackExecutor().execute_single_turn_attacks_async(  # type: ignore\n",
    "    attack=attack,\n",
    "    objectives=objectives\n",
    ")\n",
    "\n",
    "for result in results:\n",
    "    await ConsoleAttackResultPrinter().print_conversation_async(result=result)  # type: ignore"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8",
   "metadata": {},
   "source": [
    "### Using your own Initializers\n",
    "\n",
    "You can also create your own initializers and pass the path to the script in as an argument. This is really powerful. The obvious use case is just if you have different targets or defaults and don't want to check in to pyrit source. However, there are other common use cases.\n",
    "\n",
    "Imagine you are conducting a security assessment and want to include a new custom target. Yes, you could check out PyRIT in editable mode. But with initialize_scripts you don't have to. And this kind of operation can be used in front ends like GUI, CLI, etc.\n",
    "\n",
    "All you need to do is create a `PyRITInitializer` class (e.g. myinitializer.py). Then you can use `set_global_variable` and use it everywhere. Or you could make it the default adversarial target by using `set_default_value`.  \n",
    "\n",
    "\n",
    "### Additional Initializer information\n",
    "\n",
    "- For more information on how default values work, see the [default values](./default_values.md) section.\n",
    "- For more information on how initializers work, see the [initializers](./pyrit_initializer.ipynb) section"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
